/**
 * Project Name:gc_sms_mvn
 * File Name:LoginLogServiceImpl.java
 * Package Name:com.clps.dev.sms.service.log.impl
 * @date 2018-12-11 11:30:20 
 * Copyright (c) 2018, jackie.duan@clpsglobal.com All Rights Reserved.
 *
 */
package com.clps.dev.sms.service.log.impl;



import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.clps.dev.sms.common.result.ResponseResult;
import com.clps.dev.sms.common.result.ResultType;
import com.clps.dev.sms.common.service.impl.BaseServiceImpl;
import com.clps.dev.sms.dao.log.LoginLogDao;
import com.clps.dev.sms.entity.log.LoginLog;
import com.clps.dev.sms.service.log.ILoginLogService;
import com.clps.dev.sms.util.result.ResponseResultUtil;


/**
 * ClassName: LoginLogServiceImpl 
 * @description
 * @date 2018-12-11 11:30:20 
 *
 * @author jackie.duan
 * @version V1.0
 * @since JDK 1.8
 */
@Service
@Transactional
public class LoginLogServiceImpl extends BaseServiceImpl<LoginLog> implements ILoginLogService{

	@Autowired
	private LoginLogDao logDao;
	/**
	 * Creates a new instance of LoginLogServiceImpl.
	 *
	 * @param clazz
	 */
	
	public LoginLogServiceImpl() {
		super(LoginLog.class);
	}
	private Logger logger = Logger.getLogger(LoginLogServiceImpl.class);
	
	/**
	 * @see com.clps.dev.sms.service.log.ILoginLogService#queryLoginLog(java.lang.Integer)
	 */
	@Override
	public ResponseResult<LoginLog> queryLoginLog(String accountName) {
		
		LoginLog log = logDao.queryLoginLog(accountName);
		
		if(log == null) {
			return ResponseResultUtil.error(ResultType.QUERY_FAULT);
		}else {
			return ResponseResultUtil.success(ResultType.QUERY_SUCCESS,log);
		}
	}

	/**
	 * @see com.clps.dev.sms.service.log.ILoginLogService#deleteLoginLog(java.lang.Integer)
	 */
	@Override
	public ResponseResult<LoginLog> deleteLoginLog(Integer id) {
		
		return ResponseResultUtil.success(ResultType.DELETE_SUCCESS);
	}

	/**
	 * @see com.clps.dev.sms.service.log.ILoginLogService#addLoginLog(com.clps.dev.sms.entity.log.LoginLog)
	 */
	@Override
	public ResponseResult<LoginLog> addLoginLog(LoginLog loginLog) {
		if(loginLog == null) {
			logger.error("loginLog不能为空");
			return ResponseResultUtil.error(ResultType.OBJECT_NULL);
		}
		if(loginLog.getAccountName() == null || loginLog.getIp() == null) {
			logger.error("字段不能为空");
			return ResponseResultUtil.error(ResultType.INPUT_NULL);
		}
		int i = logDao.save(loginLog);
		if(i > 0) {
			return ResponseResultUtil.success(ResultType.ADD_SUCCESS);
		}else {
			return ResponseResultUtil.error(ResultType.ADD_FAULT);
		}
	}
}
